==
and ===
in JavaScriptBoth == and === are comparison operators in JavaScript, but they differ in how they compare values.
==
(Equality Operator)Example:
console.log(5 == "5"); // true (type coercion occurs)
Output: true
===
(Strict Equality Operator)true
.Example:
console.log(5 === "5"); // false (no type coercion)
Output: false
Aspect | == (Equality) |
=== (Strict Equality) |
---|---|---|
Type Conversion | Performs type conversion. | Does not perform type conversion. |
Comparison | Checks only value after type coercion. | Checks both value and type. |
Usage | Used when type conversion is acceptable. | Used when strict type matching is required. |